<?
// Get recent additions
if (!empty($optID)) {
	// Get recent additions for this option only
	// Get recent addition for the sub category 
	$sqlR = "SELECT *
		FROM ss_resource R
		LEFT JOIN ss_resourceLink L ON R.ID = L.ResourceID
		WHERE L.Sub2CatID = '$SubCatID' AND
		L.OptionID = '$optID' AND
		R.Visible = 1
		ORDER BY DateSubmit DESC
		LIMIT 4";
	$resultR = mysql_db_query($dbname,$sqlR);
	$rowsR = mysql_num_rows($resultR);
	//$linkOptID = "&optID=".$optID;
	$linkOptID = $optID;
} else {
	// Get recent addition for the sub category 
	$sqlR = "SELECT *
		FROM ss_resource R
		LEFT JOIN ss_resourceLink L ON R.ID = L.ResourceID
		WHERE L.Sub2CatID = '$SubCatID' AND
		R.Visible = 1
		ORDER BY DateSubmit DESC
		LIMIT 4";
	$resultR = mysql_db_query($dbname,$sqlR);
	$rowsR = mysql_num_rows($resultR);
}
?>

<div class="headBar">Recent Additions 
<? if ( ($rowsT > $rowsR) || ($rowsT > 4) ) { ?>
: <a href="/va/<?=$SubCatID; ?>/<?=$linkOptID; ?>">View all <?=$rowsT; ?> resources</a>
<? } ?>
</div>
<?
if (!empty($rowsR)) {
	include("includes/listResources.php");
	if ( ($rowsT > $rowsR) || ($rowsT > 4) ) {
		echo "<div align=\"right\"><img src=\"images/bullet_red.gif\">&nbsp;\n";
		//echo "<a href=\"/va/$SubCatID/$linkOptID\"><b>View all $rowsT resources</b></a></div>\n";
		echo "<a href=\"http://www.sonixshop.com/viewResourcesAll.php?subCatID=$SubCatID&optID=$linkOptID\"><b>View all $rowsT resources</b></a></div>\n";
	}
}

$totalRows = $totalRows+$rowsR;
?>